package com.liujit.upms.controller;

import com.liujit.upms.domain.params.SysPermissionParams;
import com.liujit.upms.domain.params.SysRolePermParams;
import com.liujit.upms.domain.query.SysPermissionQuery;
import com.liujit.upms.domain.result.SysPermissionResult;
import com.liujit.upms.service.SysPermissionService;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 系统权限管理接口
 * @Author liujun
 * @Date 2021-07-02 15:00:56
 */
@RequiredArgsConstructor
@Api(tags = "系统权限管理接口")
@RestController
@RequestMapping("/sys/permission")
public class SysPermissionController {

    private final SysPermissionService sysPermissionService;

    @ApiOperation(value = "分页查询", notes = "根据系统权限分页查询条件，分页查询系统权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统权限分页查询条件", dataType = "SysPermissionQuery", dataTypeClass = SysPermissionQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysPermissionResult> getPage(SysPermissionQuery query) {
        return sysPermissionService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统权限添加请求参数，添加系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统权限添加请求参数", dataType = "SysPermissionParams", dataTypeClass = SysRolePermParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysPermissionParams params) {
        return sysPermissionService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统权限修改请求参数，修改系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统权限修改请求参数", dataType = "SysPermissionParams", dataTypeClass = SysRolePermParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysPermissionParams params) {
        return sysPermissionService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统权限id，查询系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统权限id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysPermissionResult get(Long id) {
        return sysPermissionService.get(id);
    }

    @ApiOperation(value = "查询详情", notes = "根据系统权限id，查询系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统权限id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/getDetail")
    public SysPermissionResult getDetail(Long id) {
        return sysPermissionService.getDetail(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统权限删除请求参数，删除系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统权限删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysPermissionService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统权限启用请求参数，启用系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统权限启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysPermissionService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统权限禁用请求参数，禁用系统权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统权限禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysPermissionService.disabled(params);
    }
}
